package com.neuedu.elmserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.elmserver.mapper.FoodMapper;
import com.neuedu.elmserver.mapper.OrdersMapper;
import com.neuedu.elmserver.pojo.Cart;
import com.neuedu.elmserver.pojo.Food;
import com.neuedu.elmserver.pojo.Orderitem;
import com.neuedu.elmserver.mapper.OrderitemMapper;
import com.neuedu.elmserver.service.OrderitemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.elmserver.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单明细/订单快照 服务实现类
 * </p>
 *
 * @author wyh
 * @since 2024-11-07
 */
@Service
public class OrderitemServiceImpl extends ServiceImpl<OrderitemMapper, Orderitem> implements OrderitemService {
    @Autowired
    private FoodMapper foodMapper;
    @Autowired
    private OrderitemMapper orderitemMapper;
    /**
     * 查询某个用户在指定商家中的订单详情列表
     * @param orderId
     * @param
     * @return
     */
    public ResultVO getOrderitemByorderId(Integer orderId){
        //①先查询查询某个用户在指定商家中的购物车数据
        QueryWrapper qw=new QueryWrapper();//查询的条件构造器
        qw.eq("order_id",orderId);
        //System.out.println(orderId);
        List<Orderitem> listOrderitem=orderitemMapper.selectList(qw);
        //System.out.println(listOrderitem);
        //②获取到每个购物项的foodId,在根据foodId查询每个购物项的食品数据
        for(Orderitem orderitem:listOrderitem){
            Food food= foodMapper.selectById(orderitem.getFoodId());
            orderitem.setFood(food);
        }
        return ResultVO.ok("查询成功",listOrderitem);//根据主键查询信息
    }

}